import { defineStore } from 'pinia'
import { ref } from 'vue'

// 按需导出
export const usePayStore = defineStore('book-pay', () => {
  const bookId = ref()
  const orderId = ref()

  const setOrderId = (id) => {
    orderId.value = id
  }
  const removeOrderId = () => {
    orderId.value = ''
  }

  const setBookId = (id) => {
    bookId.value = id
  }
  const removeBookId = () => {
    bookId.value = ''
  }


  const orderDetail = ref({
    author: '',
    avatar: '',
    bookMoney: '',
    bookName: '',
    bookType: '',
    id: '',
  })
  const setOrderDetail = (detail) => {
    orderDetail.value.author = detail.author
    orderDetail.value.avatar = detail.avatar
    orderDetail.value.bookMoney = detail.bookMoney
    orderDetail.value.bookName = detail.bookName
    orderDetail.value.bookType = detail.bookType
    orderDetail.value.id = detail.id
  }
  const removeOrderDetail = () => {
    orderDetail.value.author = ''
    orderDetail.value.avatar = ''
    orderDetail.value.bookMoney = ''
    orderDetail.value.bookName = ''
    orderDetail.value.bookType = ''
    orderDetail.value.id = ''
  }

  const createOrder = ref({
    addressId: '',
    book_id: '',
    create_time: '',
    order_money: '',
    name: '',
    phone: '',
    provinces: '',
    city: '',
    district: '',
    detail_address: '',
    buyNumber: ''
  })
  const setOrder = (order) => {
    createOrder.value.addressId = order.addressId
    createOrder.value.book_id = order.book_id
    createOrder.value.create_time = order.create_time
    createOrder.value.name = order.name
    createOrder.value.phone = order.phone
    createOrder.value.provinces = order.provinces
    createOrder.value.city = order.city
    createOrder.value.district = order.district
    createOrder.value.detail_address = order.detail_address
    createOrder.value.buyNumber = order.buyNumber
  }
  const removeOrder = () => {
    createOrder.value.addressId = ''
    createOrder.value.book_id = ''
    createOrder.value.create_time = ''
    createOrder.value.name = ''
    createOrder.value.phone = ''
    createOrder.value.provinces = ''
    createOrder.value.city = ''
    createOrder.value.district = ''
    createOrder.value.detail_address = ''
    createOrder.value.buyNumber = ''
  }


  return {
    bookId,
    setBookId,
    removeBookId,

    createOrder,
    setOrder,
    removeOrder,

    orderDetail,
    setOrderDetail,
    removeOrderDetail,

    orderId,
    setOrderId,
    removeOrderId
  }
},
{
  persist: true,
},
)